import textgrid as tg
import os
import json
import time

test_path = '/home/asr_deploy_test/asr_test_file/Test_Ali/Test_Ali_far/textgrid_dir'
file_dict = {}

for file in os.listdir(test_path):
    path = os.path.join(test_path, file)
    file_dict[file] = path

test_dict = {}

for file, path in file_dict.items():
    total_answer = ''
    tgrid = tg.TextGrid.fromFile(path)
    total_sentence = []
    for entry in tgrid:
        sentence = []
        answer = ''
        for interval in entry:
             sentence.append(interval.mark)
        answer = answer.join(sentence)
        total_sentence.append(answer)
    name = file.replace('TextGrid', 'wav')
    test_dict[name] = total_sentence

with open ('dataset/long_sentence_test_set.json', 'w', encoding='utf-8') as f:
    json.dump(test_dict, f, ensure_ascii=False)
